<?php

if (!$_SESSION['LOGIN_OK']) {

    $t_data = array(
        "login"        => stripslashes(trim($_POST["login"])),
        "password"     => stripslashes(trim($_POST["password"])),
        "use_kcaptcha" => $_SESSION['LOGIN_TRY'],
        "kcaptcha"     => stripslashes(trim($_POST["kcaptcha"])),
        "keystring"    => $_SESSION["captcha_keystring"]);

    $LoginCheck = LoginCheck($GL, $t_data);
    if (!$LoginCheck) {
        $t_tpl = !$_SESSION['LOGIN_TRY'] ? GetTpl("login") : GetTpl("klogin");
        $t_replace = array(
            "{login}"    => $t_data["login"],
            "{password}" => $t_data["password"],
            "{result}"   => !$_SESSION['LOGIN_TRY'] ? NULL : "Введенные данные не верны",
            "{ses_name}" => $ses_name,
            "{ses_id}"   => $ses_id);
        foreach ($t_replace as $k => $v)
            $t_tpl = str_replace($k, $v, $t_tpl);
        $BODY .= $t_tpl;

        if ($_SESSION['LOGIN_TRY'])
            Logger($LogFile, "FAILED LOGIN (".$t_data["login"].")");

        $_SESSION['LOGIN_TRY']++;
    }
    else {
        $_SESSION['LOGIN_OK'] = TRUE;
        $_SESSION['LOGIN_NAME'] = $t_data["login"];
        $_SESSION['LOGIN_PASS'] = $t_data["password"];
        $_SESSION['LOGIN_UID'] = $LoginCheck["uid"];
        Logger($LogFile, "ACCEPT LOGIN (".$t_data["login"].")");
        header("Location: http://" . $SITE . "/?action=panel");
    }
}

?>
